
import {baseUrl} from './utils/config';
App({
  onLaunch() {
    console.log('app.js')
  },

  // 封装get请求
  get(url, data = {}) {
    return new Promise((resolve, reject) => {
      wx.request({
        url: baseUrl + url,
        method: 'get',
        data,
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) { 
          if (res.data.code == 666) {
            resolve(res.data)
          } else {
            reject(res.data);
          }
        },
        fail(error) { 
          reject(error);
        },
      })
    }); 
  },

  // 封装post请求
  post(url, data = {}) {
    return new Promise((resolve, reject) => {
      wx.request({
        url: baseUrl + url,
        method: 'post',
        data,
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) { 
          resolve(res.data)
        },
        fail(error) { 
          reject(error);
        },
      })
    });
  },
})
